2
Answers

extracting same result using selenium

Photo of Ilyas Zahir

Ilyas Zahir

7y
182
1
I'm extracting posts from instagram using selenium, so I get image src and its text. the problem is that while extracting it's scrape same src and different text for such post.

Here is my code
 
var options = new ChromeOptions(); options.AddArguments("--disable-gpu"); 
C#
var driverService = ChromeDriverService.CreateDefaultService(); 
C#
driverService.HideCommandPromptWindow = true; 
C#
var dr = new ChromeDriver(driverService, options); 
C#
for (int d = 0; d < listBox1.Items.Count; d++) {     
C#
dr.Navigate().GoToUrl("https://www.instagram.com/" + listBox1.Items[d].ToString());
C#
var number = dr.FindElementByClassName("_fd86t").Text; Thread.Sleep(100);    
C#
 dr.FindElementByClassName("_si7dy").Click();
C#
for (int s = 0; s < Convert.ToInt32(numericUpDown1.Value); s++) {
C#
Thread.Sleep(1000);
C#
if (dr.FindElements(By.XPath("/html/body/div[4]/div/div[2]/div/article/div[1]/div/div/div/div[2]/a")).Count != 0) {           
C#
  dr.Keyboard.SendKeys(OpenQA.Selenium.Keys.Right); }
C#
else {
C#
var src = dr.FindElementByClassName("_2di5p").GetAttribute("src");
C#
var pra = dr.FindElementByClassName("_ezgzd").FindElement(By.TagName("span")).Text;
C#
this.Invoke(new MethodInvoker(delegate () {                 
C#
dataGridView1.Rows.Add(src.ToString(), pra.ToString()); }));        
C#
dr.Keyboard.SendKeys(OpenQA.Selenium.Keys.Right); } } }
C#
 

Answers (2)

1
Photo of Jaganathan Bantheswaran
NA 21.9k 2.2m 11y
We can do that by spending sometime with jquery & CSS3. But there are lot of plugins available online so why should we waste time spend to re-create it again.

So click here to download the plugin.
Accepted
0
Photo of lucy will
NA 4 0 10y
image viewer control to enlarge an image within the web or windows at a few mouse click, simple and conveninet.
0
Photo of selva kumar
NA 582 132.5k 11y
Its Working Fine..Thank u very much...
0
Photo of selva kumar
NA 582 132.5k 11y
Its working fine but the close button does not appear on top right corner.image loading button also..